<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta content="yes" name="apple-mobile-web-app-capable">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<meta content="telephone=no" name="format-detection">
	<meta content="no-cache" http-equiv="Cache-Control">
	<title>源之东方</title>
	<link href="__STATIC__/css/shopin.css" rel="stylesheet" />
	<link href="__STATIC__/css/loading.css" rel="stylesheet" />
</head>
<style>
	.ft {
		position: relative;
	}

	.f {
		top: 18px;
		color: red;
	}
	.logistics_model{
		width: 80vw;
		margin:0 10vw;
		position: relative;
		background: white;
		z-index: 999;
		height:400px;
		top: 50%;
		border-radius: 6px;
		margin-top: -200px;
	}
	.model {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 1000;
		overflow: auto;
		background-color: rgba(0, 0, 0, 0.2);
		display: none;
	}
	.logistics_model .gb{
		font-size: 22px;
		position: absolute;
		right: 20px;
	}
</style>

<body>
<div class="header">
	<div class="left">
		<a href="javascript:;" class="a-back"><span>返回</span></a>
	</div>
	<div class="center">
		<h1>我的订单</h1>
	</div>
</div>
<!--//头部结束-->

<div class="content">
	<div class="all-order">
		{volist name="orderList" id="vo"}
		<div class="order" id="mescroll">
			<div class="hd">
				<span class="code">订单号：{$vo.order_num}</span>
			</div>
			<div class="bd">
				<div class="small">
					<a href="/product/info.html?id={$vo.gid}"  class="list-item">
						{if (substr($vo.url, 0, 1) !== 'h')}
						<div class="p"><img src="http://img.58bjcf.com/{$vo.url}"></div>
						{else}
						<div class="p"><img src="{$vo.url}"></div>
						{/if}
						<div class="d">
							<h3 class="d-title clamp">{$vo.name}</h3>
							<div class="d-main">
								<div class="sku">颜色:<span id="color">{$vo.color}</span>;尺码:<span id="size">{$vo.size}</span>;数量:x<span id="num">{$vo.num}</span></div>
								<div class="sub">
									<span class="price">
										<span class="s">小计：<em class="n">￥{$vo.oprice}</em>
									</span>
								</div>

							</div>
						</div>
					</a>
				</div>
				<!-- //单品结束 -->
			</div>
			<div class="ft">

					<!-- <a class="btn delOrder" data-id="{$vo.id}">删除订单</a> -->
					<a class="btn logistics" data-id="{$vo.order_num}">确认收货</a>
					<div class="f">
						合计金额：￥<span>{$vo.deal_price}</span>元
					</div>

			</div>

		</div>
		<!-- //订单结束 -->
		{/volist}
	</div>
	<div class="model">
		<ul class="logistics_model">
			<span class="gb">X</span>
		</ul>
	</div>
	<div class="loading">
		<span>加载中...</span>
		<div class="pswp__preloader__icn">
			<div class="pswp__preloader__cut">
				<div class="pswp__preloader__donut"></div>
			</div>
		</div>
	</div>
</div>
<script src="__STATIC__/js/zepto.min.js"></script>
<script src="__STATIC__/js/base.min.js"></script>
<script src="__STATIC__/js/shopin.js"></script>
<script>
    function getScrollTop() {
        var scrollTop = 0;
        if(document.documentElement && document.documentElement.scrollTop) {
            scrollTop = document.documentElement.scrollTop;
        } else if(document.body) {
            scrollTop = document.body.scrollTop;
        }
        return scrollTop;
    }

    function getClientHeight() {
        var clientHeight = 0;
        if(document.body.clientHeight && document.documentElement.clientHeight) {
            clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
        } else {
            clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
        }
        return clientHeight;
    }

    function getScrollHeight() {
        return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
    }

    var obj = true;

    var limit = 1;
    //滚动事件触发
    window.onscroll = function() {
        if(getScrollTop() + getClientHeight() == getScrollHeight()) {

            //此处发起AJAX请求
            $.ajax({
                type: "get",
                dataType: 'json',
                data: {
                    limit: limit
                },
                url: "/order/state/1?limit="+limit,
                async: true,
                success: function(data) {
                    var data = JSON.parse(data);
                    console.log(data);
                    limit++;
                    if(data=="" || data == null){
                        var obj = false;
                        $('.loading').show();
                        $('.loading').html('');
                        $('.loading').html('<div>大哥!这是我底线</div>');
                    }else{
                        if(data.length<5){
                            var obj = false;
                            $('.loading').show();
                            $('.loading').html('');
                            $('.loading').html('<div>大哥!这是我底线</div>');
                        }
                        var obj = false;
                        $('.loading').show();
                        for(var i = 0; i < data.length; i++) {
                            for(var k = 0; k < data[i].data.length;k++) {
                                var str =/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
                                if(!str.test(data[i].data[k]['url'])){
                                    var str1 =data[i].data[k]['url'];
                                    var str2 = 'http://img.58bjcf.com/';
                                    data[i].data[k]['url']=str2.concat(str1);
                                }else{
                                    var j = data[i].data[k]['url'];
                                    j.replace('http://img.58bjcf.com/','');
                                }
                                new_aobj = document.createElement("div");
                                new_aobj.className = 'order';
                                new_aobj.innerHTML='<div class="hd">'+
                                    '<span class="code">订单号：'+data[i]['order_no']+'</span>'+
                                    '</div>'+
                                    '<div class="bd">'+
                                    '<div class="small">'+
                                    '<a href="/product/info.html?id='+ data[i].data[k]['order_id'] +'"class="list-item">'+
                                    '<div class="p"><img src="'+data[i].data[k]['url']+'"></div>'+
                                    '<div class="d">'+
                                    '<h3 class="d-title clamp">'+data[i].data[k]['name']+'</h3>'+
                                    '<div class="d-main">'+
                                    '<div class="sku">颜色:<span id="color">'+data[i].data[k]['color']+'</span>;尺码:<span id="size">'+data[i].data[k]['size']+'</span>;数量:x<span id="num">'+data[i].data[k]['num']+'</span></div>'+
                                    '<div class="sub">'+
                                    '<span class="price">'+
                                    '<span class="s">￥<em class="n">'+data[i].data[k]['price']+'</em>(会员价)</span><del>市场价￥'+data[i].data[k]['member_price']+'</del>'+
                                    '</span>'+
                                    '</div>'+
                                    '<div class="small_plan">小计:￥<span>'+data[i].data[k]['price']*data[i].data[k]['num']+'</span>元</div>'+
                                    '</div>'+
                                    '</div>'+
                                    '</a>'+
                                    '</div>'+
                                    '</div>'+
                                    '<div class="ft">'+
                                    '<div class="btn-box">'+
                                    '<div class="f">'+
                                    '合计金额：￥<span>'+data[i].data[k]['deal_price']+'</span>元'+
                                    '</div>'+
                                    '</div>'+
                                    '</div>'
                                $('.all-order').append(new_aobj);
                            }
                        }

                    }


                },
                error: function(error) {
                    //异常处理；
                    console.log(error);
                }
            });
        }
    }

    //合计
    function total() {
        for(j = 0; j < $(".code").length; j++) {
            //获取订单下面的商品数
            len = $(".order").eq(j).children().children(".small").length;
            // jiage = 0;
            for(m = 0; m < len; m++) {
                // jia = $(".bd").eq(j).children(".small").eq(m).children().children().children().children(".small_plan").children().text();
                // jia = parseFloat(jia);
                // var xiaoji = jia.toFixed(2);
                $(".bd").eq(j).children(".small").eq(m).children().children().children().children(".small_plan").children().text();
                // jiage += parseFloat(xiaoji);
                var jiage= parseFloat($(' .f span').eq(j).text());
                var heji = jiage.toFixed(2);
                $(' .f span').eq(j).text(heji);

            }
        }
    }
    total();
    //物流
    // $(document).on('click','.logistics',function(){
    //     $('.model').show();
    //     $('.gb').on('click',function(){
    //         $('.model').hide();
    //     });
    // })
    $('.logistics').on('click',function(){
        var info= confirm('是否确认收货?');
        var order_num = $(this).attr("data-id");
        if (info) {
            $.ajax({
                type: "get",
                dataType: 'json',
                data:{
                    order_num : order_num
                },
                url: "/order/quer",
                async: true,
                success:function(data){
                    console.log(data);
                },
                error:function(error){
                    console.log(error);
                }
            })
        }
    });
</script>
</body>
